Visualization with HoloViz


Imports

import uxarray as ux
import holoviews as hv
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import hvplot.pandas

# Create blue color theme
cmap = matplotlib.colors.LinearSegmentedColormap.from_list("Color_Theme", plt.cm.Blues(np.linspace(0.2, 1, 30)))
ds_file_480 = "../meshfiles/oQU480.230422.nc"
ds_file_120 = "../meshfiles/oQU120.230424.nc"

uxds_480 = ux.open_dataset(ds_file_480, ds_file_480)
uxds_120 = ux.open_dataset(ds_file_120, ds_file_120)

Visualizing Grid Geometry

gdf_480_grid = uxds_480.uxgrid.to_geodataframe()
gdf_120_grid = uxds_120.uxgrid.to_geodataframe()

Nodes

hv.extension("matplotlib")

plot_kwargs = {"size": 5.0, "xlabel": "Longitude", "ylabel": "Latitude", "xlim": (-110, -50), "ylim": (0, 40),
               "coastline": True, "width": 800}
hv.Layout(gdf_480_grid.hvplot.points(**plot_kwargs) + gdf_120_grid.hvplot.points(**plot_kwargs)).opts(fig_size=300).cols(1)
/usr/share/miniconda3/envs/cookbook-dev/lib/python3.10/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/110m_physical/ne_110m_coastline.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
hv.extension("bokeh")

plot_kwargs = {"s": 4.0, "xlabel": "Longitude", "ylabel": "Latitude", "xlim": (-110, -50), "ylim": (0, 40),
               "coastline": True}
hv.Layout(gdf_480_grid.hvplot.points(**plot_kwargs) + gdf_120_grid.hvplot.points(**plot_kwargs)).cols(1)

Edges

hv.extension("matplotlib")

plot_kwargs = {"linewidth": 0.5, "xlabel":" Longitude", "ylabel": "Latitude", "xlim": (-110, -50), "ylim": (0, 40),
               "coastline": True, "width": 1600}
hv.Layout(gdf_480_grid.hvplot.paths(**plot_kwargs) + gdf_120_grid.hvplot.paths(**plot_kwargs)).opts(fig_size=300).cols(1)
hv.extension("bokeh")

plot_kwargs = {"line_width": 0.5, "xlabel": "Longitude", "ylabel": "Latitude", "xlim": (-110, -50), "ylim": (0, 40),
               "coastline": True}
hv.Layout(gdf_480_grid.hvplot.paths(**plot_kwargs) + gdf_120_grid.hvplot.paths(**plot_kwargs)).cols(1)

Visualizing Grid Geometry with Data

gdf_480_grid_data = uxds_480['bottomDepth'].to_geodataframe()
gdf_120_grid_data = uxds_120['bottomDepth'].to_geodataframe()
hv.extension("matplotlib")

plot_kwargs = {"c": "bottomDepth", "cmap": cmap} #TODO
# TODO: raster
hv.Layout(gdf_480_grid_data.hvplot.polygons(**plot_kwargs, rasterize=True) +
          gdf_120_grid_data.hvplot.polygons(**plot_kwargs, rasterize=True)).opts(fig_size=100).cols(1)
/usr/share/miniconda3/envs/cookbook-dev/lib/python3.10/site-packages/holoviews/operation/datashader.py:1372: UserWarning: rename 'x' to 'x' does not create an index anymore. Try using swap_dims instead or use set_index after rename to create an indexed coordinate.
  agg = agg.rename({'x': xdim.name, 'y': ydim.name})
/usr/share/miniconda3/envs/cookbook-dev/lib/python3.10/site-packages/holoviews/operation/datashader.py:1372: UserWarning: rename 'y' to 'y' does not create an index anymore. Try using swap_dims instead or use set_index after rename to create an indexed coordinate.
  agg = agg.rename({'x': xdim.name, 'y': ydim.name})
/usr/share/miniconda3/envs/cookbook-dev/lib/python3.10/site-packages/holoviews/operation/datashader.py:1372: UserWarning: rename 'x' to 'x' does not create an index anymore. Try using swap_dims instead or use set_index after rename to create an indexed coordinate.
  agg = agg.rename({'x': xdim.name, 'y': ydim.name})
/usr/share/miniconda3/envs/cookbook-dev/lib/python3.10/site-packages/holoviews/operation/datashader.py:1372: UserWarning: rename 'y' to 'y' does not create an index anymore. Try using swap_dims instead or use set_index after rename to create an indexed coordinate.
  agg = agg.rename({'x': xdim.name, 'y': ydim.name})
hv.extension("bokeh")

plot_kwargs = {"c": "bottomDepth",  "cmap": cmap, "line_width": 0.1} #TODO
# TODO: vector
hv.Layout(gdf_480_grid_data.hvplot.polygons(**plot_kwargs, rasterize=False) +
          gdf_120_grid_data.hvplot.polygons(**plot_kwargs, rasterize=False)).cols(1)
# TODO: raster
hv.Layout(gdf_480_grid_data.hvplot.polygons(**plot_kwargs, rasterize=True) +
          gdf_120_grid_data.hvplot.polygons(**plot_kwargs, rasterize=True)).cols(1)
/usr/share/miniconda3/envs/cookbook-dev/lib/python3.10/site-packages/holoviews/operation/datashader.py:1372: UserWarning: rename 'x' to 'x' does not create an index anymore. Try using swap_dims instead or use set_index after rename to create an indexed coordinate.
  agg = agg.rename({'x': xdim.name, 'y': ydim.name})
/usr/share/miniconda3/envs/cookbook-dev/lib/python3.10/site-packages/holoviews/operation/datashader.py:1372: UserWarning: rename 'y' to 'y' does not create an index anymore. Try using swap_dims instead or use set_index after rename to create an indexed coordinate.
  agg = agg.rename({'x': xdim.name, 'y': ydim.name})
/usr/share/miniconda3/envs/cookbook-dev/lib/python3.10/site-packages/holoviews/operation/datashader.py:1372: UserWarning: rename 'x' to 'x' does not create an index anymore. Try using swap_dims instead or use set_index after rename to create an indexed coordinate.
  agg = agg.rename({'x': xdim.name, 'y': ydim.name})
/usr/share/miniconda3/envs/cookbook-dev/lib/python3.10/site-packages/holoviews/operation/datashader.py:1372: UserWarning: rename 'y' to 'y' does not create an index anymore. Try using swap_dims instead or use set_index after rename to create an indexed coordinate.
  agg = agg.rename({'x': xdim.name, 'y': ydim.name})
/usr/share/miniconda3/envs/cookbook-dev/lib/python3.10/site-packages/holoviews/operation/datashader.py:1372: UserWarning: rename 'x' to 'x' does not create an index anymore. Try using swap_dims instead or use set_index after rename to create an indexed coordinate.
  agg = agg.rename({'x': xdim.name, 'y': ydim.name})
/usr/share/miniconda3/envs/cookbook-dev/lib/python3.10/site-packages/holoviews/operation/datashader.py:1372: UserWarning: rename 'y' to 'y' does not create an index anymore. Try using swap_dims instead or use set_index after rename to create an indexed coordinate.
  agg = agg.rename({'x': xdim.name, 'y': ydim.name})
/usr/share/miniconda3/envs/cookbook-dev/lib/python3.10/site-packages/holoviews/operation/datashader.py:1372: UserWarning: rename 'x' to 'x' does not create an index anymore. Try using swap_dims instead or use set_index after rename to create an indexed coordinate.
  agg = agg.rename({'x': xdim.name, 'y': ydim.name})
/usr/share/miniconda3/envs/cookbook-dev/lib/python3.10/site-packages/holoviews/operation/datashader.py:1372: UserWarning: rename 'y' to 'y' does not create an index anymore. Try using swap_dims instead or use set_index after rename to create an indexed coordinate.
  agg = agg.rename({'x': xdim.name, 'y': ydim.name})